package com.scm.erp.framework.tools;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * 内置网络验证工具
 */
@Component
public class CloudDetectionTools {
    /**
     * @param Card 身份证ID
     * @return true 为身份证格式正常 false 为身份证格式错误
     */
    public Boolean cloudCard (String Card){
        Document document = null;
        try {
            document = Jsoup.connect("http://www.dffyw.com/sfzcx/query.php?id=" + Card).timeout(200000).get();
            String text = document.body().html();
            JSONArray jsonFkDmgBanJson = JSONObject.parseArray("[" + text +"]");
            if(jsonFkDmgBanJson.isEmpty()==false){
                JSONObject JsonFkDmgBanJson = JSONObject.parseObject(jsonFkDmgBanJson.get(0).toString());
                String isText = (String) JsonFkDmgBanJson.get("Error");
                return isText.equals("")?true:false;
            }else {
                return false;
            }
        }catch (Exception e){e.printStackTrace();}
        return false;
    }
}
